<#include "/common/common.ftl"> <@html>
<style type="text/css">
.container {
	width: 150px;
	height: 300px;
	border: solid 1px black;
	text-align: center;
}

.dojoDndItem {
	padding: 3px;
}

.dj_ff2 .dojoDndItem {
	-moz-user-select: none;
	/* workaround FF2 dragging bug, see #6345, #4854, #6350 */
}

.dojoDndItemOver {
	background: #ededed;
	cursor: pointer;
}

.dojoDndItemSelected {
	background: #ccf;
	color: #444;
}

.dojoDndItemAnchor {
	background: #ccf;
	color: black;
}

.dojoDndItemOver .dojoDndItemSelected {
	background: #ededed;
}

.dojoDndItemOver .dojoDndItemAnchor {
	background: #ededed;
}

.dojoDndItemBefore {
	border-top: 2px solid #369;
}

.dojoDndItemAfter {
	border-bottom: 2px solid #369;
}

.dojoDndAvatar {
	border: 2px solid #ccc;
	font-size: 75%;
	-moz-border-radius: 8pt 8pt;
	radius: 8pt;
}

.dojoDndAvatarHeader {
	background: #aaa;
}

.dojoDndAvatarItem {
	background: #fff;
	border-bottom: 1px solid #666;
}
</style>
<script type="text/javascript">
	dojo.require("dijit.dijit"); // optimize: load dijit layer
	dojo.require("dijit.form.Form");
	dojo.require("dijit.form.ValidationTextBox");
	dojo.require("dijit.form.DateTextBox");
	dojo.require("dijit.form.TextBox");
	dojo.require("dojo.dnd.Source");
</script>
<form jsId="detailForm" id="detailForm" method="post" dojoType="dijit.form.Form">
	<input type="hidden" name="id" value="${id!}" />
	<TABLE class=queryTable cellSpacing=0 width="100%" align=center
		border=0>
		<tr>
			<th width="9%">
			</th>
			<th width="18%">
			</th>
			<th width="9%">
			</th>
			<th width="18%">
			</th>
			<th width="9%">
			</th>
			<th width="25%">
			</th>
		</tr>
		<tr>
			<td class="right">
				用户名<@splitor/>
				</label>
			</td>
			<td>
				<input name="domain.userCode" dojoType="dijit.form.ValidationTextBox"
					style="width: 120px" required="true" promptMessage="请输入用户编号"
					invalidMessage="只能是英文字母或数字" regExp="^\w+$" id="userCode"
					value="${(domain.userCode)!}" />
			</Td>
			<td class="right">
				<label>
					用户名称<@splitor/>
				</label>
			</td>
			<td>
				<input name="domain.userName" dojoType="dijit.form.ValidationTextBox"
					type="text" style="width: 240px;" required="true"
					promptMessage="请输入用户名称" invalidMessage="" id="userName"
					value="${(domain.userCode)!}" />
			</td>
			<td width="9%" class="right">
				<label>
					所属公司<@splitor/>
				</label>
			</td>
			<td>
				<select name="domain.companyId">
					<option></option>
				</select>
			</td>
		</tr>
		<tr>
			<td class="right">
				<label>
					密码<@splitor/>
				</label>
			</td>
			<td>
				<input name="domain.password" dojoType="dijit.form.ValidationTextBox"
					type="password" style="width: 120px;" regExp="^\w{6,20}$"
					required="true" promptMessage="请输入密码"
					invalidMessage="请输入6-20位数字或字母!" id="password" value="${(domain.userCode)!}" />
			</td>
			<td class="right">
				<label>
					重复密码<@splitor/>
				</label>
			</td>
			<td>
				<input name="password2" dojoType="dijit.form.ValidationTextBox"
					type="password" regExp="^\w{6,20}$" style="width: 120px;"
					required="true" promptMessage="请输入密码"
					invalidMessage="请输入6-20位数字或字母!" id="password2" value="${(domain.userCode)!}" />
			</td>
			<td class="right">
				<label>
					到期日期<@splitor/>
				</label>
			</td>
			<td>
				<input id="expireDate" dojoType="dijit.form.DateTextBox"
					value="${getDate(domain.userCode)}" style="width: 65px;" required="true"
					name="domain.expireDate"
					constraints="{min:'2011-01-01', max:'2020-12-31'}" />
			</td>
		</tr>
	</TABLE>
	<div style="width:100%;height:400px">
		<div style="float: left;padding-left: 240px; text-align: center;margin-right:10px;">
			<h3>
				未分配角色
			</h3>
			<div dojoType="dijit.form.Button" onClick="c1.selectAll();">
				全选
			</div>
			<div dojoType="dojo.dnd.Source" jsId="c1" class="container">
				<#if unDistributeRoles??> <#list unDistributeRoles as ops>
				<div value="${ops.value!}" class="dojoDndItem">
					${ops.text!}
				</div>
				</#list> </#if>
			</div>
		</div>
		<div style="float: left; text-align: center;margin-left:10px;">
			<h3>
				已分配角色
			</h3>
			<div dojoType="dijit.form.Button" onClick="c2.selectAll();">
				全选
			</div>
			<div dojoType="dojo.dnd.Source" jsId="c2" class="container">
				<#if distributeRoles??> <#list distributeRoles as ops>
				<div value="${ops.value!}" class="dojoDndItem">
					${ops.text!}
				</div>
				</#list> </#if>
			</div>
		</div>
	</div>
	</form>
	<@listButton/>
	<script type="text/javascript">
	dojo.subscribe('btnSave.click', null, function() {
		//校验表单
		if(detailForm.validate()){
			var selectedRoles = [];
			dojo.query('.dojoDndItem',c2.domNode).forEach(function(item){
				selectedRoles.push(dojo.attr(item,'value'));
			})
			var param = dojo.mixin({"userRoles":selectedRoles.join(',')},dojo.formToObject(dojo.byId('detailForm')))
			dojo.xhrPost( {
				url : "${path}/system/user.save.do",
				content : param,
				handleAs : "json",
				load : function(json) {
					window.parent.Info("操作成功！", function() {
						window.parent.publish("save");
						window.parent.closeDialog();
					});
				}
			})
		}
	});
</script>
</@html>
